class BankAccount {
    private int balance;
    private boolean isOpen;
//    private final Object lockObj = new Object();

    synchronized void open() {
        this.isOpen = true;
    }

    int getBalance() throws BankAccountActionInvalidException {
        if (!this.isOpen) {
            throw new BankAccountActionInvalidException("Account closed");
        }

        return this.balance;
    }

    synchronized void deposit(int deposits) throws BankAccountActionInvalidException {
        if (!this.isOpen) {
            throw new BankAccountActionInvalidException("Account closed");
        }

        if (deposits < 0) {
            throw new BankAccountActionInvalidException("Cannot deposit or withdraw negative amount");
        }
        this.balance += deposits;
    }

    synchronized void withdraw(int withdrawals) throws BankAccountActionInvalidException {
        if (!this.isOpen) {
            throw new BankAccountActionInvalidException("Account closed");
        }

        if (withdrawals < 0) {
            throw new BankAccountActionInvalidException("Cannot deposit or withdraw negative amount");
        }


        if (this.balance == 0) {
            throw new BankAccountActionInvalidException("Cannot withdraw money from an empty account");
        }

        if (this.balance < withdrawals) {
            throw new BankAccountActionInvalidException("Cannot withdraw more money than is currently in the account");
        }

        this.balance -= withdrawals;

    }

    synchronized void close() {
        this.isOpen = false;
    }
}
